import axios from 'axios'
import { getLocal, setLocal } from './help'
import { getHost } from './config'


axios.defaults.baseURL = getHost()

//axios.defaults.withCredentials = true
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
axios.defaults.headers['token'] = getLocal('token') || ''
axios.defaults.headers.post['Content-Type'] = 'application/json'

axios.interceptors.response.use(res => {

    // 如果返回结果的resultCode不等于200
    if (res.data.resultCode != 200) {

      // 抛出一个带有返回结果data的拒绝Promise对象
      //return Promise.reject(res.data)
      return res
    }

    return res.data
  })

export default axios